package query_infrastructure

import (
	"github.com/liuxd6825/dapr-ddd-cli/pkg/builds"
	"github.com/liuxd6825/dapr-ddd-cli/pkg/config"
)

type BuildRepositoryImplTestUnit struct {
	builds.BaseBuild
	entity *config.Entity
}

func NewBuildRepositoryImplTestUnit(base builds.BaseBuild, entity *config.Entity, dbType, outFile string) *BuildRepositoryImplTestUnit {
	res := &BuildRepositoryImplTestUnit{
		BaseBuild: base,
		entity:    entity,
	}
	res.ValuesFunc = res.Values
	res.TmplFile = "static/tmpl/go/init/pkg/query-service/infrastructure/domain/repository_impl/" + dbType + "/repository_impl_test.go.tpl"
	res.OutFile = outFile
	return res
}

func (b *BuildRepositoryImplTestUnit) Values() map[string]interface{} {
	values := b.BaseBuild.ValuesOfEntity(b.entity)
	if b.entity != nil {
		allProperties := config.NewProperties(b.entity.Aggregate, &b.entity.Properties, nil)
		defPros := b.entity.Aggregate.Config.GetDefaultEntityProperties()
		allProperties.Adds(defPros)
		defPros = b.entity.Aggregate.Config.GetDefaultViewProperties()
		allProperties.Adds(defPros)
		values["AllProperties"] = allProperties
	} else {
		allProperties := config.NewProperties(b.Aggregate, &b.Aggregate.Properties, nil)
		defPros := b.Aggregate.Config.GetDefaultEntityProperties()
		allProperties.Adds(defPros)
		defPros = b.Aggregate.Config.GetDefaultViewProperties()
		allProperties.Adds(defPros)
		values["AllProperties"] = allProperties
	}
	return values
}
